//
//  UUNotificationCommonCell.m
//  UUCharterSupplier
//
//  Created by ZhangAo on 06/03/2018.
//  Copyright © 2018 UUCharter. All rights reserved.
//

#import "UUNotificationCommonCell.h"
#import "UUPermissionUtility.h"
#import "UUCarManager.h"

@interface UUNotificationCommonCell ()

@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation UUNotificationCommonCell

- (void)setupWithModel:(UUNotificationModel *)model {
    [super setupWithModel:model];
    
    if (self.titleLabel == nil) {
        self.titleLabel = [UILabel new];
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        self.titleLabel.textColor = COMMON_TEXT_BLACK_COLOR;
        [self.containerContentView addSubview:self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.top.mas_equalTo(17);
            make.height.mas_equalTo(23);
        }];
    }
    
    while (self.containerContentView.subviews.count > 1) {
        [self.containerContentView.subviews.lastObject removeFromSuperview];
    }
    
    NSArray<UUFormItemMode *> *fields = nil;
    switch (model.content.type) {
        case UUNotificationContentTypeIntentOrder: {
            self.titleLabel.text = @"即时报价提醒";
            UUNotificationContentIntentOrderModel *content = (UUNotificationContentIntentOrderModel *)model.content;
            NSString *carNum = [NSString stringWithFormat:@"%d辆", content.busNum];
            fields = @[
                       [UUFormItemMode itemWithTitle:@"时间" content:[content.departTime formatDateByFormatString:@"yyyy.MM.dd HH:mm"]],
                       [UUFormItemMode itemWithTitle:@"出发地" content:content.departure.address],
                       [UUFormItemMode itemWithTitle:@"到达地" content:content.arrival.address],
                       [UUFormItemMode itemWithTitle:@"数量" content:carNum],
                       [UUFormItemMode itemWithTitle:@"天数" content:[NSString daysToDisplayString:content.days]]
                       ];
        }
            break;
        case UUNotificationContentTypeOrderConfirm:
        case UUNotificationContentTypeOrderCancel: {
            if (model.content.type == UUNotificationContentTypeOrderCancel) {
                self.titleLabel.text = @"订单取消提醒";
            } else {
                self.titleLabel.text = @"订单确认提醒";
            }
            UUNotificationContentOrderConfirmModel *content = (UUNotificationContentOrderConfirmModel *)model.content;
            NSString *carNum = [NSString stringWithFormat:@"%d辆", content.busNum];
            fields = @[
                       [UUFormItemMode itemWithTitle:@"时间" content:[content.departTime formatDateByFormatString:@"yyyy.MM.dd HH:mm"]],
                       [UUFormItemMode itemWithTitle:@"出发地" content:content.departure.address],
                       [UUFormItemMode itemWithTitle:@"到达地" content:content.arrival.address],
                       [UUFormItemMode itemWithTitle:@"数量" content:carNum],
                       [UUFormItemMode itemWithTitle:@"天数" content:[NSString daysToDisplayString:content.days]],
                       [UUFormItemMode itemWithTitle:@"价格" content:[content.price toCurrency]]
                       ];
        }
            break;
        case UUNotificationContentTypeOrderService:
        case UUNotificationContentTypeOrderAssign: {
            if (model.content.type == UUNotificationContentTypeOrderAssign) {
                self.titleLabel.text = @"订单分配提醒";
            } else {
                self.titleLabel.text = @"订单服务提醒";
            }
            UUNotificationContentOrderServiceModel *content = (UUNotificationContentOrderServiceModel *)model.content;
            NSString *carNum = [NSString stringWithFormat:@"%d辆", content.busNum];
            fields = @[
                       [UUFormItemMode itemWithTitle:@"时间" content:[content.departTime formatDateByFormatString:@"yyyy.MM.dd HH:mm"]],
                       [UUFormItemMode itemWithTitle:@"出发地" content:content.departure.address],
                       [UUFormItemMode itemWithTitle:@"数量" content:carNum],
                       [UUFormItemMode itemWithTitle:@"天数" content:[NSString daysToDisplayString:content.days]],
                       [UUFormItemMode itemWithTitle:@"联系人" content:content.contact],
                       [UUFormItemMode itemWithTitle:@"联系电话" content:content.contactMobile]
                       ];
        }
            break;
        case UUNotificationContentTypeWithdrawFailure: {
            self.titleLabel.text = @"提现失败提醒";
            UUNotificationContentWithdrawFailureModel *content = (UUNotificationContentWithdrawFailureModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"提现时间" content:[content.createTime formatDateByFormatString:@"yyyy.MM.dd HH:mm"]],
                       [UUFormItemMode itemWithTitle:@"提现金额" content:[content.money toCurrency]],
                       [UUFormItemMode itemWithTitle:@"失败原因" content:content.remark]
                       ];
        }
            break;
        case UUNotificationContentTypeWithdrawSuccess: {
            self.titleLabel.text = @"提现成功提醒";
            UUNotificationContentWithdrawSuccessModel *content = (UUNotificationContentWithdrawSuccessModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"提现时间" content:[content.createTime formatDateByFormatString:@"yyyy.MM.dd HH:mm"]],
                       [UUFormItemMode itemWithTitle:@"提现金额" content:[content.money toCurrency]],
                       ];
        }
            break;
        case UUNotificationContentTypeProductReviewSuccess: {
            self.titleLabel.text = @"审核通过提醒";
            UUNotificationContentProductAuditPassModel *content = (UUNotificationContentProductAuditPassModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"审核类型" content:@"包车产品"],
                       [UUFormItemMode itemWithTitle:@"审核内容" content:content.carType]
                       ];
        }
            break;
        case UUNotificationContentTypeCarReviewSuccess: {
            self.titleLabel.text = @"审核通过提醒";
            UUNotificationContentCarAuditPassModel *content = (UUNotificationContentCarAuditPassModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"审核类型" content:@"车辆信息"],
                       [UUFormItemMode itemWithTitle:@"审核内容" content:content.carNum]
                       ];
        }
            break;
        case UUNotificationContentTypeProductReviewFailure: {
            self.titleLabel.text = @"审核拒绝提醒";
            UUNotificationContentProductAuditFailtureModel *content = (UUNotificationContentProductAuditFailtureModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"审核类型" content:@"包车产品"],
                       [UUFormItemMode itemWithTitle:@"审核内容" content:content.carType],
                       [UUFormItemMode itemWithTitle:@"失败原因" content:content.remark]
                       ];
        }
            break;
        case UUNotificationContentTypeCarReviewFailure: {
            self.titleLabel.text = @"审核拒绝提醒";
            UUNotificationContentCarAuditFailtureModel *content = (UUNotificationContentCarAuditFailtureModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"审核类型" content:@"车辆信息"],
                       [UUFormItemMode itemWithTitle:@"审核内容" content:content.carNum],
                       [UUFormItemMode itemWithTitle:@"失败原因" content:content.remark]
                       ];
        }
            break;
        case UUNotificationContentTypeKeeperUnregister: {
            self.titleLabel.text = @"管理员注销提醒";
            UUNotificationContentKeeperLogoutModel *content = (UUNotificationContentKeeperLogoutModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"注销账号" content:content.account],
                       [UUFormItemMode itemWithTitle:@"管理员姓名" content:content.name],
                       [UUFormItemMode itemWithTitle:@"管理员角色" content:[UUPermissionUtility roleNameForRoleId:content.role]],
                       ];
        }
            break;
        case UUNotificationContentTypeSupplierReviewSuccess:
            self.titleLabel.text = @"审核提醒";
            fields = @[
                       [UUFormItemMode itemWithTitle:@"审核内容" content:@"供应商信息"],
                       [UUFormItemMode itemWithTitle:@"审核状态" content:@"审核通过"]
                       ];
            break;
        case UUNotificationContentTypeSupplierReviewFailure: {
            self.titleLabel.text = @"审核提醒";
            UUNotificationContentSupplierReviewFailureModel *content = (UUNotificationContentSupplierReviewFailureModel *)model.content;
            fields = @[
                       [UUFormItemMode itemWithTitle:@"审核内容" content:@"供应商信息"],
                       [UUFormItemMode itemWithTitle:@"审核状态" content:@"审核失败"],
                       [UUFormItemMode itemWithTitle:@"失败原因" content:content.remark]
                       ];
        }
            break;
        default:
            DKAssert(0);
    }
    
    UUFormView *formView = [[UUFormView alloc] initWithItems:fields];
    [self.containerContentView addSubview:formView];
    [formView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
    }];
}

@end
